`
https://leetcode.cn/problems/triangle/
`

/**
 * @param {number[][]} triangle
 * @return {number}
 */
var minimumTotal = function (triangle) {
  const n = triangle.length
  const dp = Array.from({ length: n }, () => new Array(n).fill(Infinity))

  dp[0][0] = triangle[0][0]

  for (let i = 1; i < triangle.length; i++) {
    const row = triangle[i]
    for (let j = 0; j < row.length; j++) {
      if (j - 1 < 0) {
        dp[i][j] = dp[i - 1][j] + row[j]
        continue
      }
      dp[i][j] = Math.min(dp[i - 1][j], dp[i - 1][j - 1]) + row[j]
    }
  }

  return Math.min(...dp[n - 1])
};